/*
 * Animation.h
 *
 *  Created on: 30/05/2013
 *      Author: vitor
 */

#ifndef ANIMATION_H_
#define ANIMATION_H_

#include "Sprite.h"
#include <string>
#include "Timer.h"
#include <algorithm>

class Animation: public Sprite {
private:
	int _numberOfSpritesInEachRow[15];
	int _numRows;
	int _currentRow;
	int _spriteWidth;
	int _spriteHeight;
	Timer _frameTimer;
	int _currentFrame;
	int _frameTimeInMilliseconds;
	bool _repeat;
	bool _ended;

public:
	Animation(std::string fileName, int frameTimeInMilliseconds, int numRows,
			int* numberOfSpritesInEachRow, int spriteWidth, bool repeat);
	virtual ~Animation();

	void update(double dt);
	virtual void render(int x, int y, bool center, SDL_Surface *destSurf =
			SDLBase::getScreen());
	void reset();
	void setFrame(int frame);
	void setCurrentRow(int row);
	bool ended() const;

	int getFrameTime() const {
		return _frameTimeInMilliseconds;
	}

	void setFrameTime(int frameTime) {
		this->_frameTimeInMilliseconds = std::max(1, frameTime);
	}

};

#endif /* ANIMATION_H_ */
